package com.example.monitor.model.DO;

import com.example.monitor.model.enums.Gender;
import com.example.monitor.model.enums.WorkerStatus;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Data;
import org.hibernate.annotations.GenericGenerator;

import jakarta.persistence.*;
import java.util.Date;

@Data
@Entity
@Table(name = "workers")
public class Worker {
    @Id
    @GeneratedValue(generator = "uuid2")
    @GenericGenerator(name = "uuid2", strategy = "uuid2")
    @Column(name = "worker_id", length = 36)
    private String workerId;

    @Column(nullable = false, length = 50)
    private String name;

    @Column(nullable = false, length = 50)
    private String workshop;

    @Enumerated(EnumType.STRING)
    @JsonIgnore
    private Gender gender;

    @Column(length = 20)
    private String phone;

    @Enumerated(EnumType.STRING)
    private WorkerStatus status = WorkerStatus.ACTIVE;

    // 添加 JSON 序列化/反序列化配置
    @JsonCreator
    public static Gender forValue(String value) {
        if (value == null) return null;
        return Gender.fromString(value); // 使用你之前写的方法
    }

    @JsonValue
    public String toValue() {
        return this.gender != null ? this.gender.getCode() : null;
    }
}